package com.ruoyi.recycle.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.recycle.domain.RecycleHandbook;
import com.ruoyi.recycle.service.IRecycleHandbookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.HtmlUtils;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 回收指南Controller
 *
 * @author Wubk
 * @date 2022-05-22
 */
@RestController
@RequestMapping("/handbook")
@Api(tags = "回收指南")
public class RecycleHandbookController extends BaseController {
    @Autowired
    private IRecycleHandbookService recycleHandbookService;

    /**
     * 查询回收指南列表
     */
    @RequiresPermissions("recycle:handbook:list")
    @GetMapping("/list")
    @ApiOperation("查询回收指南列表")
    public TableDataInfo list(RecycleHandbook recycleHandbook) {
        startPage();
        List<RecycleHandbook> list = recycleHandbookService.selectRecycleHandbookList(recycleHandbook);
        return getDataTable(list);
    }

    /**
     * 导出回收指南列表
     */
    @RequiresPermissions("recycle:handbook:export")
    @Log(title = "回收指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出回收指南列表")
    public void export(HttpServletResponse response, RecycleHandbook recycleHandbook) {
        List<RecycleHandbook> list = recycleHandbookService.selectRecycleHandbookList(recycleHandbook);
        ExcelUtil<RecycleHandbook> util = new ExcelUtil<RecycleHandbook>(RecycleHandbook.class);
        util.exportExcel(response, list, "回收指南数据");
    }

    /**
     * 获取回收指南详细信息
     */
    @RequiresPermissions("recycle:handbook:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取回收指南详细信息")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long")
    @ApiResponse(code = 200, message = "成功", response = RecycleHandbook.class)
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(recycleHandbookService.selectRecycleHandbookById(id));
    }

    /**
     * 新增回收指南
     */
    @RequiresPermissions("recycle:handbook:add")
    @Log(title = "回收指南", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增回收指南")
    public AjaxResult add(@RequestBody RecycleHandbook recycleHandbook) {
        return toAjax(recycleHandbookService.save(recycleHandbook));
    }

    /**
     * 修改回收指南
     */
    @RequiresPermissions("recycle:handbook:edit")
    @Log(title = "回收指南", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改回收指南")
    public AjaxResult edit(@RequestBody RecycleHandbook recycleHandbook) {
        return toAjax(recycleHandbookService.updateById(recycleHandbook));
    }

    /**
     * 删除回收指南
     */
    @RequiresPermissions("recycle:handbook:remove")
    @Log(title = "回收指南", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除回收指南")
    @ApiImplicitParam(name = "ids", value = "id集合", dataType = "List")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(recycleHandbookService.deleteRecycleHandbookByIds(ids));
    }
}
